import {
    post,
    get,
    put,
    Delete,
    form
} from "@/axios/http.js";
import {
    basicApi
} from "@/api/index.js"
import { setCookie, removeCookie, getCookie } from "@/utils/auth";
//模块数据
export default {
    namespaced: true,
    state: {
        // 学生空间进班级，学校空间，显示我的空间
        studentToSpace: false,
        // 全局消息通知标记
        messageDot: getCookie('messageDot') ? getCookie('messageDot') : false,
        // 分页插件参数统一配置
        paginationParams: {
            currentPage: 1,
            pageSizes: [10, 20, 30, 40],
            pageSize: 10,
            layout: "total, sizes, prev, pager, next, jumper",
            total: 30,
        },
        changeToList: false, // 切换时强制跳会list显示，避免富文本出错
        isManager: getCookie('isManager') ? getCookie('isManager') : false, //是不是该界面管理员
        isShowManagement: false, //是否打开管理中心
        // 权限列表
        permissionArr: [{
                id: 5,
                name: "所有人"
            },
            {
                id: 6,
                name: "仅自己"
            },
            {
                id: 7,
                name: "好友可见"
            },
            {
                id: 8,
                name: "关注可见"
            }
        ],
        addGroupFlag: false,
        flushTreeFlag: false,
    },
    actions: {
        // 我的任务列表
        myTask({
            commit
        }, params) {
            return post(basicApi.common.myTask, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 个人空间访问权限-返回成功即能访问
        checkVisitor({
            commit
        }, params) {
            return get(basicApi.common.checkVisitor, params).then(res => {
                // if (res.data.code == 200) {
                return res
                    // } else {
                    // this._vm.$message.error('没有访问权限')
                    // }
            });
        },
        // 应用--用户角色权限所对应的应用
        getApplication({
            commit
        }, params) {
            return get(basicApi.common.getApplication, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 首页tab菜单
        menuTab({
            commit
        }, params) {
            return get(basicApi.common.menuTab, params).then(res => {
                return res
            });
        },
        // 通知消息通知
        messageNotice({
            commit
        }, params) {
            return get(basicApi.common.messageNotice, params).then(res => {
                return res
            });
        },
        // 通用消息通知
        messageCommon({
            commit
        }, params) {
            return get(basicApi.common.messageCommon, params).then(res => {
                return res
            });
        },
        // 确认消息通知
        messageComfirm({
            commit
        }, params) {
            return get(basicApi.common.messageComfirm, params).then(res => {
                return res
            });
        },
        // 上传单张图片信息,注意：图片的name必须为file
        uploadImage({
            commit
        }, params) {
            return post(basicApi.common.uploadImage, params).then(res => {
                return res
            });
        },
        // 上传图片-批量，注意：多图上传时每个图片的name必须保证唯一
        uploadImages({
            commit
        }, params) {
            return post(basicApi.common.uploadImages, params).then(res => {
                return res
            });
        },
    },
    mutations: {
        // 分页参数变动时处理
        INIT_PAGINATIONPARAMS(state, params) {
            if (params) {
                state.paginationParams[params.type] = params.val
            }
        },
        // 分页参数变动时处理
        INIT_STUDENTTOSPACE(state, params) {
            state.studentToSpace = params
        },
        INIT_MESSAGEDOT(state, params) {
            if (params == 'true') {
                state.messageDot = true
            } else {
                state.messageDot = false
            }
            setCookie('messageDot', state.messageDot)
        },
        INIT_ISSHOWMANAGEMENT(state, params) {
            state.isShowManagement = params
        },
        INIT_ISMANAGER(state, params) {
            state.isManager = params
            setCookie('isManager', state.isManager)
        },

        CHANGE_ADDGROUPFLAG(state, params) {
            if (params) {
                state.addGroupFlag = params
            } else {
                state.addGroupFlag = !state.addGroupFlag
            }
        },
        CHANGE_FLUSHTREEFLAG(state, params) {
            if (params) {
                state.flushTreeFlag = params
            } else {
                state.flushTreeFlag = !state.flushTreeFlag
            }
        },
        CHANGETOLIST(state, params) {
            state.changeToList = !state.changeToList
        }
    },
};